<template>
  <view class="container_mime screen-width">
    <view class="header">
      <view class="content u-flex u-row-between">
        <view class="u-flex" @click="toRoute('/pages/mime/profile')">
          <img :src="info.avatar.indexOf('http') > -1 ? info.avatar : $imgUrl + info.avatar" />
          <view class="name-wrap u-m-l-40">
            <view class="name">{{ info.nickName || '--' }}</view>
            <view>{{ identity }}</view>
          </view>
        </view>
        <view @tap="isCard" class="card">
          <view class="text">个人名片</view>
        </view>
        <u-icon name="arrow-right"></u-icon>
      </view>
      <view class="btn u-m-t-40">
        <u-image src="/static/mine/vip.png" :height="80" @click="goVipPage"></u-image>
      </view>
    </view>
    <view class="body u-m-t-30">
      <u-cell-group>
        <u-cell-item title="会员中心" :center="true" :arrow="false" @click="toRoute('/pages/mime/center')">
          <u-image slot="icon" class="u-m-r-40" src="/static/mine/icon_1.png" width="40" height="40"></u-image>
          <u-icon slot="right-icon" name="arrow-right" color="#daeaf5"></u-icon>
        </u-cell-item>
        <u-cell-item title="我的消息" :center="true" :arrow="false" @click="toRoute('/pages/mime/message')">
          <u-image slot="icon" class="u-m-r-40" src="/static/mine/icon_2.png" width="40" height="40"></u-image>
          <u-icon slot="right-icon" name="arrow-right" color="#daeaf5"></u-icon>
        </u-cell-item>
        <u-cell-item title="我的名片" :center="true" :arrow="false" @click="toRoute('/pages/person/CardList')">
          <u-image slot="icon" class="u-m-r-40" src="/static/mine/card.png" width="40" height="40"></u-image>
          <u-icon slot="right-icon" name="arrow-right" color="#daeaf5"></u-icon>
        </u-cell-item>
        <u-cell-item title="名片收藏" :center="true" :arrow="false" @click="toRoute('/pages/mime/card')">
          <u-image slot="icon" class="u-m-r-40" src="/static/mine/icon_3.png" width="40" height="40"></u-image>
          <u-icon slot="right-icon" name="arrow-right" color="#daeaf5"></u-icon>
        </u-cell-item>
        <u-cell-item title="我的关注" :center="true" :arrow="false" @click="toRoute('/pages/mime/follow')">
          <u-image slot="icon" class="u-m-r-40" src="/static/mine/icon_4.png" width="40" height="40"></u-image>
          <u-icon slot="right-icon" name="arrow-right" color="#daeaf5"></u-icon>
        </u-cell-item>
        <u-cell-item title="商业计划书测评列表" :center="true" :arrow="false" @click="toRoute('/pages/mime/business')">
          <u-image slot="icon" class="u-m-r-40" src="/static/mine/icon_11.png" width="50" height="50"></u-image>
          <u-icon slot="right-icon" name="arrow-right" color="#daeaf5"></u-icon>
        </u-cell-item>
        <u-cell-item title="活动列表" :center="true" :arrow="false" @click="toRoute('/pages/activity/createList/Index')">
          <u-image slot="icon" class="u-m-r-40" src="/static/mine/icon_11.png" width="50" height="50"></u-image>
          <u-icon slot="right-icon" name="arrow-right" color="#daeaf5"></u-icon>
        </u-cell-item>
        <u-cell-item title="我的企业" :center="true" :arrow="false" @click="toRoute('/pages/mime/company')">
          <u-image slot="icon" class="u-m-r-40" src="/static/mine/icon_5.png" width="40" height="40"></u-image>
          <u-icon slot="right-icon" name="arrow-right" color="#daeaf5"></u-icon>
        </u-cell-item>
        <u-cell-item title="会员订单" :center="true" :arrow="false" @click="toRoute('/pages/mime/order')">
          <u-image slot="icon" class="u-m-r-40" src="/static/mine/icon_6.png" width="40" height="40"></u-image>
          <u-icon slot="right-icon" name="arrow-right" color="#daeaf5"></u-icon>
        </u-cell-item>
        <u-cell-item title="商品订单" :center="true" :arrow="false" @click="toRoute('/pages/mime/productOrder')">
          <u-image slot="icon" class="u-m-r-40" src="/static/mine/icon_6.png" width="40" height="40"></u-image>
          <u-icon slot="right-icon" name="arrow-right" color="#daeaf5"></u-icon>
        </u-cell-item>
        <u-cell-item title="联系客服" :center="true" :arrow="false" @click="toRoute('/pages/mime/service')">
          <u-image slot="icon" class="u-m-r-40" src="/static/mine/icon_9.png" width="40" height="40"></u-image>
          <u-icon slot="right-icon" name="arrow-right" color="#daeaf5"></u-icon>
        </u-cell-item>
        <u-cell-item title="浏览历史" :center="true" :arrow="false" @click="toRoute('/pages/mime/searchHistory')">
          <u-image slot="icon" class="u-m-r-40" src="/static/mine/icon_10.png" width="40" height="40"></u-image>
          <u-icon slot="right-icon" name="arrow-right" color="#daeaf5"></u-icon>
        </u-cell-item>
      </u-cell-group>
    </view>
    <view class="footer" @tap="logout">
      <view class="btn">退出登录</view>
    </view>
    <Festival></Festival>
  </view>
</template>

<script>
  import { userInfo } from '../../util/api/user'

  export default {
    data() {
      return {
        info: {}, // 用户信息
      }
    },
    computed: {
      identity() {
        switch (this.info.identityType) {
          case 1:
            return '企业主'
          case 2:
            return '服务机构'
          case 3:
            return '其他'
        }
      },
    },

    onShow() {
      this.getToken()
    },
    methods: {
      // 退出登录
      logout() {
        this.$removeToken()
        uni.setStorageSync('pageUrl', window.location.href)
        uni.navigateTo({
          url: '/pages/login/index',
        })
      },
      // 去vip页
      goVipPage() {
        uni.navigateTo({
          url: '/pages/VIP/index',
        })
      },
      toRoute(url) {
        uni.navigateTo({
          url,
        })
      },
      // 获取用户信息
      getUserInfo() {
        userInfo().then(res => {
          this.info = res.result
        })
      },
      getToken() {
        // 获取token
        let token = this.$getToken()
        if (!token) {
          uni.setStorageSync('pageUrl', window.location.href)
          // uni.navigateTo({
          //   url: "/pages/login/index"
          // });
          uni.showModal({
            title: '提示',
            content: '您还没有登录，请登录后操作！',
            cancelText: '取消', // 取消按钮的文字
            confirmText: '去登录', // 确认按钮文字
            confirmColor: '#1678ff',
            success: res => {
              if (res.confirm) {
                uni.navigateTo({
                  url: `/pages/login/index`,
                })
              } else {
                console.log(22)
                uni.switchTab({
                  url: `/pages/index/index`,
                })
              }
            },
          })
        } else {
          this.getUserInfo()
        }
      },
      toRouteQues() {
        uni.navigateTo({
          url: `/pages/questionnaire/index?id=1529281250312953857`,
        })
      },
      // 去名片
      isCard() {
        let token = this.$getToken()
        if (!token) {
          uni.showToast({
            title: '请登录后,再操作',
            duration: 2000,
            iocn: 'none',
          })
          uni.setStorageSync('pageUrl', window.location.href)
          uni.navigateTo({
            url: '/pages/login/index',
          })
        } else {
          uni.navigateTo({
            url: '/pages/person/CardList',
          })
        }
      },
    },
  }
</script>

<style lang="less" scope>
  .container_mime {
    // height: auto;
    padding-bottom: 10rpx;
    // height: calc(100vh - 120rpx);

    .footer {
      margin: 0 auto;
      margin-top: 80rpx;
      margin-bottom: 138rpx;
      width: 410rpx;
      height: 64rpx;
      line-height: 64rpx;
      text-align: center;

      .btn {
        background: #1678ff;
        height: 100%;
        border-radius: 8rpx;
        color: #fff;
      }
    }

    .header {
      background-image: url('/static/mine/bg.png');
      width: 100%;
      height: 312rpx;
      padding: 40rpx 30rpx 12rpx 30rpx;
      img {
        width: 140rpx;
        height: 140rpx;
        border-radius: 50%;
      }
      .name-wrap {
        font-size: 26rpx;
        font-family: PingFang SC, PingFang SC-Regular;
        font-weight: 400;
        text-align: left;
        color: #aaaaaa;

        .name {
          font-size: 36rpx;
          font-family: PingFang SC, PingFang SC-Bold;
          font-weight: 700;
          text-align: left;
          color: #333333;
        }
      }
      .card {
        background: #1678ff;
        opacity: 0.7;
        color: #ffffff;
        font-size: 24upx;
        padding: 8upx 10upx;
        border-radius: 50upx;
      }
    }
  }
</style>
